import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_project/common/route_page/route_name.dart';
import 'package:flutter_project/user/user_login/user_login_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../config/theme_color.dart';
import '../../config/web_page.dart';
import '../../generated/l10n.dart';
import '../splash/guide_swiper_page.dart';

class AgreePrivacyPage extends StatelessWidget {
  const AgreePrivacyPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),
        color: Colors.white,
      ),
      margin: const EdgeInsets.symmetric(horizontal: 40, vertical: 160),
      child: Material(
        color: Colors.transparent,
        child: Column(
          children: [
            const SizedBox(
              height: 33,
            ),
            const Text(
              '用户需知',
              style: TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                  color: Colors.black),
            ),
            Expanded(
              child: SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    const SizedBox(height: 20),
                    Container(
                      padding: const EdgeInsets.symmetric(horizontal: 20),
                      child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                              text:
                                  '欢迎您使用${S.of(context).appTitle}APP。请你务必审慎阅读，充分理解用户协议和隐私政策各条款，包括但不限于用户注意事项、用户行为规范以及个人信息的收集与使用等情况。\n\n详细信息你可阅读'),
                          TextSpan(
                            text: '《用户协议》',
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                RouteNames.push(
                                  const WebPage(
                                    url: 'assets/html/UserPolicy.html',
                                    title: '用户协议',
                                  ),
                                );
                              },
                            style: TextStyle(color: ThemeColor.mainColor),
                          ),
                          const TextSpan(text: '、'),
                          TextSpan(
                            text: '《隐私政策》',
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                RouteNames.push(
                                  const WebPage(
                                    url: 'assets/html/PrivacyPolicy.html',
                                    title: '隐私政策',
                                  ),
                                );
                              },
                            style: TextStyle(color: ThemeColor.mainColor),
                          ),
                          TextSpan(
                            text: '《个人信息收集清单》',
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                RouteNames.push(
                                  const WebPage(
                                    url: 'assets/html/PersonInfoCollect.html',
                                    title: '个人信息收集清单',
                                  ),
                                );
                              },
                            style: TextStyle(color: ThemeColor.mainColor),
                          ),
                          TextSpan(
                            text: '《申请使用权限》',
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                RouteNames.push(
                                  const WebPage(
                                    url: 'assets/html/ApplyUserRight.html',
                                    title: '申请使用权限',
                                  ),
                                );
                              },
                            style: TextStyle(color: ThemeColor.mainColor),
                          ),
                          const TextSpan(
                              text:
                                  '了解。如你同意，请点击下方按钮开始接受我们的服务。\n\n我们可能会申请以下权限：\n\n访问您的相机/相册，用于选择并生成新图片/视频。此权限不会默认开启，您有权拒绝或取消授权。\n\n访问本地存储，用以帮助您生成图片/视频内容。此权限不会默认开启，您有权拒绝或取消授权。'),
                        ], style: const TextStyle(color: Colors.black)),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            const SizedBox(
              height: 18,
            ),
            GestureDetector(
              onTap: () {
                shareSave();
                // RouteNames.pushReplacement(const GuideSwiperPage());
                RouteNames.pushReplacement(const UserLoginView());
              },
              child: Container(
                  margin: const EdgeInsets.symmetric(horizontal: 20),
                  padding: const EdgeInsets.symmetric(vertical: 10),
                  decoration: BoxDecoration(
                      color: ThemeColor.mainColor,
                      borderRadius: BorderRadius.circular(20)),
                  alignment: Alignment.center,
                  child: const Text(
                    '同意',
                    style: TextStyle(
                        color: Colors.white, fontWeight: FontWeight.bold),
                  )),
            ),
            const SizedBox(
              height: 10,
            ),
            GestureDetector(
              onTap: () {
                SystemNavigator.pop();
              },
              child: Text(
                '不同意并退出',
                style: TextStyle(color: ThemeColor.checkNormalColor),
              ),
            ),
            const SizedBox(
              height: 20,
            ),
          ],
        ),
      ),
    );
  }

  void shareSave() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setBool('hasAgree', true);
  }
}
